package com.zut.edu;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.qmuiteam.qmui.layout.QMUILinearLayout;
import com.qmuiteam.qmui.util.QMUIStatusBarHelper;
import com.qmuiteam.qmui.widget.QMUITopBarLayout;
import com.qmuiteam.qmui.widget.roundwidget.QMUIRoundButton;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RegisterFirstActivity extends AppCompatActivity implements View.OnClickListener{

    String type;
    @BindView(R.id.register_first_button)
    QMUIRoundButton registerfirstbutton;
    @BindView(R.id.register_first_phonetext)
    EditText registerfirstphonetext;
    @BindView(R.id.registerfirst_back)
    ImageView registerfirstback;
    @BindView(R.id.register_first_layout)
    QMUILinearLayout registerfirstlayout;
    @BindView(R.id.reg_first_title)
    TextView regfirsttitle;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_registerfirst);
        ButterKnife.bind(this);
        QMUIStatusBarHelper.translucent(this);//沉浸式
        QMUIStatusBarHelper.setStatusBarLightMode(this);
        Intent intent = getIntent();
        type = intent.getStringExtra("type");
        setListener();
        EditLayout();
        switch (type){
            case "register":regfirsttitle.setText("账号注册");
                break;
            case "tologin":regfirsttitle.setText("手机登录");
                break;
            case "appeal":regfirsttitle.setText("账号申诉");
                break;
        }
    }
    private void setListener(){
        registerfirstbutton.setOnClickListener(this);
        registerfirstphonetext.setOnClickListener(this);
        registerfirstback.setOnClickListener(this);
    }
    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.register_first_button:
                int length = registerfirstphonetext.getText().toString().trim().length();
                if(length!=11){
                    Toast.makeText(this,  "请输入合法手机号码", Toast.LENGTH_SHORT).show();
                    return;
                }
                switch (type){
                    case "register":
                        Intent intent = new Intent(RegisterFirstActivity.this,RegisterSecondActivity.class);
                        intent.putExtra("phone",registerfirstphonetext.getText().toString().trim());
                        intent.putExtra("type","register");
                        startActivity(intent);
                        break;
                    case "tologin":
                        Intent intent1 = new Intent(RegisterFirstActivity.this,RegisterSecondActivity.class);
                        intent1.putExtra("phone",registerfirstphonetext.getText().toString().trim());
                        intent1.putExtra("type","tologin");
                        startActivity(intent1);
                        break;
                    case "appeal":
                        Intent intent2 = new Intent(RegisterFirstActivity.this,RegisterSecondActivity.class);
                        intent2.putExtra("phone",registerfirstphonetext.getText().toString().trim());
                        intent2.putExtra("type","appeal");
                        startActivity(intent2);
                        break;
                    default:
                        break;
                }
                break;
            case R.id.registerfirst_back:
                super.onBackPressed();
                break;
        }
    }

    private void EditLayout(){
        registerfirstlayout.setBorderColor(getResources().getColor(R.color.qmui_config_color_black));
        registerfirstlayout.setBorderWidth(1);
        registerfirstlayout.setRadius(25);

        registerfirstbutton.setChangeAlphaWhenPress(true);

    }
}
